# FIRST SECTION: used by every dialogue
# SECOND SECTION: first dialogue;
#                 if there's a new dialogue after, it has two additional commands towards the end to remove tag of old dialogue and add new one
# THIRD SECTION: second dialogue

# TAGS TO CHANGE = all the words in capital letters:
#                                                   NPCX is the tag of the npc that has these dialogues
#                                                   DIALOGUE<X> is the tag for each dialogue (given by commands outside of the dialogues)
#                                                   LINES<X> is the tag used by the dialogue with the same number (given and removed by the dialogue's commands)

# OTHER THINGS TO CHANGE: the lines themselves in the tellraw commands and their matching tp commands
#                         where the dialogue_stand armor stands are spawned (make sure the npc is facing in the right direction)
#                         if you add more lines, change the max number of "scores={dialogue=<Y>}", to make it match the total number of lines for each dialogue
# Remember that each tellraw command also has a tp commands to make the player face the right npc

# In the 4 commands that use NPCX_DIALOGUE<X>, you can put other requisites: for example, you can require a previous tag to not be present by using "tag=!<NAME>"



execute as @e[tag=active,scores={dialogue=1},tag=NPCX] at @s if entity @p[tag=fade_out_end] run tag @a remove stop

execute as @e[tag=active,scores={dialogue=1},tag=NPCX] at @s if entity @p[tag=fade_in_end] run tag @a add npc

execute as @e[tag=active,scores={dialogue=1},tag=NPCX] at @s if entity @p[tag=fade_stands] run summon armor_stand ^1.2 ^ ^2.1 {Marker:true,NoGravity:true,Invisible:true,Tags:["dialogue_stand","facing_npc"]}
execute as @e[tag=active,scores={dialogue=1},tag=NPCX] at @s if entity @p[tag=fade_stands] run summon armor_stand ^ ^ ^1.5 {Marker:true,NoGravity:true,Invisible:true,Tags:["dialogue_stand","player_puppet"]}
execute as @e[tag=active,scores={dialogue=1},tag=NPCX] at @s if entity @p[tag=fade_stands] run execute as @e[tag=player_puppet] at @s run tp @s ~ ~ ~ facing entity @e[tag=NPCX,limit=1,sort=nearest]
execute as @e[tag=active,scores={dialogue=1},tag=NPCX] at @s if entity @p[tag=fade_stands] run summon armor_stand ^1.2 ^ ^-0.6 {Marker:true,NoGravity:true,Invisible:true,Tags:["dialogue_stand","facing_puppet"]}

execute as @e[tag=active,scores={dialogue=1},tag=NPCX] at @s if entity @p[tag=fade_start] run tag @e[tag=NPCX] remove npc




execute as @e[tag=active,scores={dialogue=1},tag=DIALOGUE1] at @s if entity @p[scores={right=2}] run tag @a add dissolve_start
execute as @e[tag=active,scores={dialogue=1},tag=DIALOGUE1] at @s if entity @p[tag=fade_in_end] run tag @a add LINES1

execute as @e[tag=active,scores={dialogue=1},tag=DIALOGUE1] at @s run execute at @e[tag=facing_npc] run tp @a[tag=!fade_out_F] ~ ~ ~ facing entity @e[tag=NPCX,limit=1,sort=nearest]
execute as @e[tag=active,scores={dialogue=1},tag=DIALOGUE1] at @s if entity @p[tag=fade_in_end] run tellraw @a ["",{"text":"Test fade?"}]

execute as @e[tag=active,scores={dialogue=1},tag=LINES1] at @s run execute at @e[tag=facing_puppet] run tp @a ~ ~ ~ facing entity @e[tag=player_puppet,limit=1,sort=nearest]
execute as @e[tag=active,scores={dialogue=2},tag=LINES1] at @s run execute at @e[tag=facing_npc] run tp @a ~ ~ ~ facing entity @e[tag=NPCX,limit=1,sort=nearest]

execute as @e[tag=active,scores={dialogue=1},tag=LINES1] at @s if entity @p[scores={right=2}] run tellraw @a ["",{"text":"Yes"}]
execute as @e[tag=active,scores={dialogue=2},tag=LINES1] at @s if entity @p[scores={right=2}] run tellraw @a ["",{"text":"Ok"}]

execute as @e[tag=active,scores={dialogue=3},tag=LINES1] at @s if entity @p[scores={right=2}] run tag @a add dissolve_end

execute as @e[tag=active,scores={dialogue=3..},tag=LINES1] at @s if entity @p[tag=fade_in_start] run execute at @e[tag=player_puppet] run tp @e[tag=stop_player] ~ ~ ~ facing entity @e[tag=NPCX,limit=1,sort=nearest]
execute as @e[tag=active,scores={dialogue=3..},tag=LINES1] at @s if entity @p[tag=fade_in_start] run execute at @e[tag=player_puppet] run tp @a ~ ~ ~ facing entity @e[tag=NPCX,limit=1,sort=nearest]
execute as @e[tag=active,scores={dialogue=3..},tag=LINES1] at @s if entity @p[tag=fade_in_start] run kill @e[tag=dialogue_stand]
execute as @e[tag=active,scores={dialogue=3..},tag=LINES1] at @s if entity @p[tag=fade_in_end] run tag @s remove npc
execute as @e[tag=active,scores={dialogue=3..},tag=LINES1] at @s if entity @p[tag=fade_in_end] run tag @e[tag=NPCX] add npc


execute as @e[tag=active,scores={dialogue=3..},tag=LINES1] at @s if entity @p[tag=fade_out_end] run tag @e[tag=NPCX] remove DIALOGUE1
execute as @e[tag=active,scores={dialogue=3..},tag=LINES1] at @s if entity @p[tag=fade_out_end] run tag @e[tag=NPCX] add DIALOGUE2


execute as @e[tag=active,scores={dialogue=3..},tag=LINES1] at @s if entity @p[tag=fade_in_end] run tag @s remove LINES1




execute as @e[tag=active,scores={dialogue=1},tag=DIALOGUE2] at @s if entity @p[scores={right=2}] run tag @a add dissolve_start
execute as @e[tag=active,scores={dialogue=1},tag=DIALOGUE2] at @s if entity @p[tag=fade_in_end] run tag @a add LINES2

execute as @e[tag=active,scores={dialogue=1},tag=DIALOGUE2] at @s run execute at @e[tag=facing_npc] run tp @a[tag=!fade_out_F] ~ ~ ~ facing entity @e[tag=NPCX,limit=1,sort=nearest]
execute as @e[tag=active,scores={dialogue=1},tag=DIALOGUE2] at @s if entity @p[tag=fade_in_end] run tellraw @a ["",{"text":"Test again?"}]

execute as @e[tag=active,scores={dialogue=1},tag=LINES2] at @s run execute at @e[tag=facing_puppet] run tp @a ~ ~ ~ facing entity @e[tag=player_puppet,limit=1,sort=nearest]
execute as @e[tag=active,scores={dialogue=2},tag=LINES2] at @s run execute at @e[tag=facing_npc] run tp @a ~ ~ ~ facing entity @e[tag=NPCX,limit=1,sort=nearest]

execute as @e[tag=active,scores={dialogue=1},tag=LINES2] at @s if entity @p[scores={right=2}] run tellraw @a ["",{"text":"Last one!"}]
execute as @e[tag=active,scores={dialogue=2},tag=LINES2] at @s if entity @p[scores={right=2}] run tellraw @a ["",{"text":"Ok"}]

execute as @e[tag=active,scores={dialogue=3},tag=LINES2] at @s if entity @p[scores={right=2}] run tag @a add dissolve_end

execute as @e[tag=active,scores={dialogue=3..},tag=LINES2] at @s if entity @p[tag=fade_in_start] run execute at @e[tag=player_puppet] run tp @e[tag=stop_player] ~ ~ ~ facing entity @e[tag=NPCX,limit=1,sort=nearest]
execute as @e[tag=active,scores={dialogue=3..},tag=LINES2] at @s if entity @p[tag=fade_in_start] run execute at @e[tag=player_puppet] run tp @a ~ ~ ~ facing entity @e[tag=NPCX,limit=1,sort=nearest]
execute as @e[tag=active,scores={dialogue=3..},tag=LINES2] at @s if entity @p[tag=fade_in_start] run kill @e[tag=dialogue_stand]
execute as @e[tag=active,scores={dialogue=3..},tag=LINES2] at @s if entity @p[tag=fade_in_end] run tag @s remove npc
execute as @e[tag=active,scores={dialogue=3..},tag=LINES2] at @s if entity @p[tag=fade_in_end] run tag @e[tag=NPCX] add npc

execute as @e[tag=active,scores={dialogue=3..},tag=LINES2] at @s if entity @p[tag=fade_in_end] run tag @s remove LINES2